package com.easylinkin.sm.entity;

import io.swagger.annotations.ApiModelProperty;
import java.util.Date;
import javax.persistence.AttributeOverride;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.Size;
import lombok.Data;
import lombok.experimental.FieldNameConstants;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import site.morn.boot.data.entity.ReviserEntity;
import site.morn.data.Displayable;

/**
 * 日志实体
 *
 * @author yezhihao
 * @since 1.0.0, 2019/8/19
 */
@Data
@Entity
@DynamicInsert
@DynamicUpdate
@FieldNameConstants
@Table(name = "sm_log")
@AttributeOverride(name = "modifier", column = @Column(name = "modifier_", length = 50))
@AttributeOverride(name = "modifyTime", column = @Column(name = "modify_time_"))
@AttributeOverride(name = "creator", column = @Column(name = "creator_", length = 50))
@AttributeOverride(name = "createTime", column = @Column(name = "create_time_"))
public class Log extends ReviserEntity implements Displayable {

  @Min(Long.MIN_VALUE)
  @Max(Long.MAX_VALUE)
  @Id
  @ApiModelProperty("日志ID")
  @Column(name = "log_id_")
  @GeneratedValue
  private Long id;

  @ApiModelProperty("客户ID")
  @Column(name = "customer_id_")
  private Long customerId;

  @ApiModelProperty("模块ID")
  @Column(name = "module_id_")
  private Long moduleId;

  @Size(max = 4000)
  @ApiModelProperty("日志信息")
  @Column(name = "content_", length = 4000)
  private String content;

  /**
   * 操作者IP
   */
  @Column(name = "ip_")
  @ApiModelProperty("操作者IP")
  private String ip;

  @ApiModelProperty("操作结果")
  @Column(name = "status_")
  private Boolean status;

  @ApiModelProperty("请求信息")
  @Lob
  @Basic(fetch = FetchType.LAZY)
  @Column(name = "request_information_")
  private String requestInformation;

  @ApiModelProperty("响应信息")
  @Lob
  @Basic(fetch = FetchType.LAZY)
  @Column(name = "response_information_")
  private String responseInformation;

  @ApiModelProperty("失败信息")
  @Lob
  @Basic(fetch = FetchType.LAZY)
  @Column(name = "fail_information_")
  private String failInformation;

  /**
   * 开始时间
   */
  @Transient
  private Date beginTime;

  /**
   * 结束时间
   */
  @Transient
  private Date endTime;

  /**
   * 显示状态
   */
  @Column(name = "display_")
  private Boolean display;


}
